<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户沟通记录信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body>
		<form id="cst_comm_rec_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
			        <div class="label">沟通时间</div>
			        <div class="field">
			            <input name="commDt" id="commDt" type="text" class="ui-datepicker" value="" validate="{required:true}">
			            <span class="requiredSymbol">*</span>
			        </div>
			    </div>
			    <div class="fieldBox col_50">
			         <div class="label">沟通方式</div>
			         <div class="field">
			              <select name="commWayCd" id="commWayCd" data-value="" >
			                   <c:forEach items="${searchSelectCommWayCdList }" var="kv" begin="0" step="1" varStatus="status">
									<c:if test="${status.index == 0}">
										<option value="${kv.key }" checked >${kv.value }</option>
									</c:if>
									<c:if test="${status.index != 0}">
										<option value="${kv.key }">${kv.value }</option>
									</c:if>
								</c:forEach>
			              </select>
			              <span class="requiredSymbol">*</span>
			         </div>
			    </div>
				<div class="fieldBox col_50">
					<div class="label">责任人</div>
					<div class="field">
						<input name="respPsn" id="respPsn" type="text" class="ui-textbox"
							value="" validate="{required:true,nmcharacter:true,maxlength:20}">
						<span class="requiredSymbol">*</span>
					</div>
				</div>
				<div class="fieldBox col_50">
					<div class="label">联系人</div>
					<div class="field">
						<input name="linkman" id="linkman" type="text" class="ui-textbox"
							value="" validate="{required:true,nmcharacter:true,maxlength:20}">
						<span class="requiredSymbol">*</span>
					</div>
				</div>
				
				<div class="fieldBox col_50">
                    <div class="label">联系电话</div>
                    <div class="field">
                        <input name="contactNum" id="contactNum" type="text" class="ui-textbox" value="" validate="{required:true,mobileAndFixedPhone: true, maxlength:20}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                
                <div class="fieldBox col_100">
                    <div class="label">简要记录</div>
                    <div class="field">
                        <textarea name="briefRec" id="briefRec" rows="4" class="l-textarea" style="width:92%" validate="{maxlength:498}"></textarea>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">反馈记录</div>
                    <div class="field">
                        <textarea name="feedbackRec" id="feedbackRec" rows="4" class="l-textarea" style="width:92%" validate="{maxlength:248}"></textarea>
                    </div>
                </div>  
                 <div class="fieldBox col_100">
                    <div class="label">成因说明</div>
                    <div class="field">
                        <textarea name="rsnDesc" id="rsnDesc" rows="4" class="l-textarea" style="width:92%" validate="{maxlength:248}"></textarea>
                    </div>
                </div>                          
                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name=cstId id="cstId" type="text" class="ui-textbox" value="${cstId}">
		              <input name="cId" id="cId" type="text" class="ui-textbox" value="${cId}">
		          </div>
		        </div>
            </div>
        </form>
	<script>
	
		$(function() {
			initData();
			initEvent();
		});
		
		//初始化数据
		function initData(){
			initFormData();
			initForm();
    	}
		
		//初始化事件
		function initEvent(){
			
		}
		
		//初始化表单
		function initForm(){
			$("#cst_comm_rec_form").ligerForm({
           	 validate: true
       		});
		}
		
		//父级窗口回调
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
	
		//新增修改
		function save(){
	            var ligerForm = liger.get("cst_comm_rec_form");
	            if (!ligerForm.valid()) {
	                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
	                return false; //验证不通过，不执行以下代码
	            }
	            var data = ligerForm.getData();
	            var cId = $("#cId").val();
	            var url = '<%=path%>/customer/cstcommrec/add.do';
	            if(cId != ""){
	            	url = '<%=path%>/customer/cstcommrec/modify.do';
	            	data["id"]= cId;
	            }
	            var wait_dialog= $.ligerDialog.SQalert({
		            content: LogUtils.LOG_CMM_LOADING,
		            SQ_type: "waitting",
		            onClose: function () {
		            }
		        });

	            
	            //设置客户ID
	            var cstId = $("#cstId").val();
	            data["commDt"] = $("#commDt").val();
	            data["cstId"]= cstId;
	            $.ajax({
	        		type: 'post',
	        		dataType:'json',
	        		data:data,
	        		url: url,
	        		success:function(msg){
	        			wait_dialog.close();
	        			 if(msg.success == 1){
	        				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	        				 parent.grid.setParm("cstId",cstId);
	        				 parent.grid.reload();
	        				 frameElement.dialog.close();
	        			 }else{
	        				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	        			 }
	        		}
	        	});
		}
	
		//初始化FORM 数据
		function initFormData(){
			var cId = $("#cId").val();
	    	if(!cId)return;
	    	 var wait_dialog= $.ligerDialog.SQalert({
		            content: LogUtils.LOG_CMM_LOADING,
		            SQ_type: "waitting",
		            onClose: function () {
		            }
		        });
	    	var _url = '<%=path%>/customer/cstcommrec/getById.do';
	    	$.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{id:cId},
	    		url: _url,
	    		success:function(msg){
	    			wait_dialog.close();
	    			 if(msg.success == 1){
	    				 setData(msg.data);//设置数据
	    			 }else{
	    				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			 }
	    		}
	    	});
		}
		
		//设置页面数据
	    function setData(data){
	    	var form = new liger.get("cst_comm_rec_form");
	    	form.setData({
	    		commWayCd:data.commWayCd,
	    		respPsn:data.respPsn,
	    		linkman:data.linkman,
	    		contactNum:data.contactNum,
	    		briefRec:data.briefRec,
	    		feedbackRec:data.feedbackRec,
	    		rsnDesc:data.rsnDesc
	    	});
	    	
	    	if(data.commDt){
				var date = new Date(data.commDt);
				var dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
				$("#commDt").val(dateStr);
			}
		};
		
	</script>

</body>
</html>